﻿@{
    ViewBag.Title = "首页汇总";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}


<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <span class="label label-success pull-right">今天</span>
                    <h5>支付金额</h5>
                </div>
                <div class="ibox-content">
                    <h1 class="no-margins text-success" id="val-pay-amount">0.00</h1>
                    <div class="stat-percent font-bold text-success" id="val-pay-count">
                        0 
                    </div>
                    <small>记录数</small>
                </div>
            </div>
        </div>
        <div class="col-sm-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <span class="label label-info pull-right">今天</span>
                    <h5>进场数</h5>
                </div>
                <div class="ibox-content">
                    <h1 class="no-margins text-info" id="val-pool-amount">0</h1>
                    <div class="stat-percent font-bold text-info" id="val-pool-count">
                        0
                    </div>
                    <small>记录数</small>
                </div>
            </div>
        </div>
        <div class="col-sm-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <span class="label label-danger pull-right">今天</span>
                    <h5>出场数</h5>
                </div>
                <div class="ibox-content">
                    <h1 class="no-margins text-danger" id="val-unpool-amount">0</h1>
                    <div class="stat-percent font-bold text-danger" id="val-unpool-count">
                        0
                    </div>
                    <small>记录数</small>
                </div>
            </div>
        </div> 
    </div> 
    
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="jqGrid_wrapper">
                        <table id="grid"></table>
                        <div id="grid_pager"></div>
                    </div>
                </div>
            </div>                
        </div>
    </div>
</div>

@section BodyFooter{
<script>
    $(document).ready(function () {

        $("#grid").jqGrid({
            url: '/Report/RealtimeOrders/',
            multiselect: false,
            colNames: ["订单号", "姓名", "车牌号", "支付金额", "支付状态", "物业", "停车场", "支付时间", "创建时间"],
            colModel: [{
                name: "order_id",
                index: "order_id",
                key: true,
            },
            {
                name: "Wxuser_name",
                index: "Wxuser_name",
                width: 80
            },
            {
                name: "car_no",
                index: "car_no",
                width: 80
            },
            {
                name: "total_fee",
                index: "total_fee",
                align: 'right',
                width: 70,
                formatter: "currency"
            },
            {
                name: "pay_status",
                index: "pay_status",
                formatter: formatPayStatus,
                width: 70
            },
             {
                 name: "Enterprise_Name",
                 index: "Enterprise_Name",
                 width: 80
             },
              {
                  name: "CCEnterprise_Name",
                  index: "CCEnterprise_Name",
                  width: 80
              },
            {
                name: "pay_time",
                index: "pay_time",
                width: 120,
                formatter: 'date',
                formatoptions: { newformat: 'Y-m-d H:i:s' }
            },
            {
                name: "create_time",
                index: "create_time",
                width: 120,
                formatter: 'date',
                formatoptions: { newformat: 'Y-m-d H:i:s' }
            }],
            caption: "实时支付记录（最近24小时）"
        });

        $(window).bind("resize",
        function () {
            var b = $(".jqGrid_wrapper").width();
            $("#grid").setGridWidth(b)
        });

        reloadPaySummaryData();

        window.setInterval("reloadData()", 10 * 1000);
    });

    var reloadPaySummaryData = function(){
        $.postJsonAjax('/Report/SummaryData', {}, function (data) {
            $('#val-pay-amount').html(data.PayAmount);
            $('#val-pay-count').html(data.PayCount);
            $('#val-pool-amount').html(data.inCount);
            $('#val-pool-count').html(data.inCount);
            $('#val-unpool-amount').html(data.outCount);
            $('#val-unpool-count').html(data.outCount);
        });
    }

    //重新加载实时充值数据
    var reloadPayData = function () {
        $("#grid").jqGrid('setGridParam', {
            page: 1
        }).trigger("reloadGrid"); //重新载入

    };

    var reloadData = function () {
        reloadPaySummaryData();
        reloadPayData();
    }
    
     
    var formatPayStatus = function (cellvalue, options, row) {
        if (cellvalue == 1) {
            return '<span class="label label-default">未支付</span>';
        }
        if (cellvalue == 2 || cellvalue == 3) {
            return '<span class="label label-success">已支付</span>';
        }
        return '';
    }
</script>
}
